extends ModbusSpatial


var speed = 1;
var max_extension = 1.0;
var extension = 0;
var min_shaft_len = 0.1; # godot does not like zero-lenth things

func _physics_process(delta):
	var needs_to_extend = ms.get_coil()
	#var needs_to_extend = false
	#var just_to_read = ms.get_coil()
	#print(needs_to_extend)

	if needs_to_extend and extension < max_extension:
		extension = clamp($PusherHandle.translation.x/2.0 + speed * delta, 0, max_extension)
		$PusherHandle.translation.x = extension * 2
		$shaft_handle.scale.y = max(extension, min_shaft_len)
	if !needs_to_extend and extension > 0:
		extension = clamp($PusherHandle.translation.x/2.0 - speed * delta, 0, max_extension)
		$PusherHandle.translation.x = extension * 2
		$shaft_handle.scale.y = max(extension, min_shaft_len)
